package com.admin.business.venusOaHardwareCapacities;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 设备设施
 * @create: 2022-03-24 11:14:55
 **/
@Service("venusOaHardwareCapacities")
@Slf4j
public class VenusOaHardwareCapacitiesService{

    @Resource
    VenusOaHardwareCapacitiesDao venusOaHardwareCapacitiesDao;

    /**
     * 添加设备设施,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人id
     *                   - device_name:设备名称
     *                   - device_type:设备型号
     *                   - device_number:设备编号
     *                   - sn_number:设备序列号
     *                   - mainboard:主板版本
     *                   - number_ver:编码版本
     *                   - wed_ver:web版本
     *                   - plugin_ver:Plugin版本
     *                   - pas_gu:通道个数
     *                   - hard_gu:硬盘个数
     *                   - alarm_enter:报警输入个数
     *                   - zb_attribute:主板版本属性
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return addVenusOaHardwareCapacities(CDO cdoRequest) {
        venusOaHardwareCapacitiesDao.addVenusOaHardwareCapacities(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新设备设施数据
     *
     * @param cdoRequest - id:主键
     *                   - org_id:企业id
     *                   - pro_id:项目id
     *                   - user_id:操作人id
     *                   - device_name:设备名称
     *                   - device_type:设备型号
     *                   - device_number:设备编号
     *                   - sn_number:设备序列号
     *                   - mainboard:主板版本
     *                   - number_ver:编码版本
     *                   - wed_ver:web版本
     *                   - plugin_ver:Plugin版本
     *                   - pas_gu:通道个数
     *                   - hard_gu:硬盘个数
     *                   - alarm_enter:报警输入个数
     *                   - zb_attribute:主板版本属性
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return updateVenusOaHardwareCapacitiesById(CDO cdoRequest) {
        int affectedRows = venusOaHardwareCapacitiesDao.updateVenusOaHardwareCapacitiesById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除设备设施数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return deleteVenusOaHardwareCapacitiesById(CDO cdoRequest){
        int affectedRows = venusOaHardwareCapacitiesDao.deleteVenusOaHardwareCapacitiesById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除设备设施数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return deleteVenusOaHardwareCapacities(CDO cdoRequest) {
        int affectedRows = venusOaHardwareCapacitiesDao.deleteVenusOaHardwareCapacities(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取设备设施数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return getVenusOaHardwareCapacitiesById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacitiesById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取设备设施数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return getVenusOaHardwareCapacities(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacities(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取设备设施数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return getVenusOaHardwareCapacitiesList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacitiesList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacitiesListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取设备设施数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-03-24 11:14:55
     */
    @OpenApi
    public Return getVenusOaHardwareCapacitiesListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacitiesListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaHardwareCapacitiesDao.getVenusOaHardwareCapacitiesListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
